package com.lzx.payment.controller;

import com.lzx.common.utils.R;
import com.lzx.payment.service.AliPayService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author 程序员星星
 * @date 2022/12/19
 * @Description
 */
@Slf4j
@RestController
@RequestMapping("/payment/aliPay")
public class AliPayController {
    @Resource
    private AliPayService aliPayService;

    //根据账单类型和日期获取账单url地址
    @GetMapping("/bill/downloadUrl/query/{billDate}/{type}")
    public R queryTradeBill(@PathVariable String billDate, @PathVariable String type) {
        log.info("获取账单url");
        String downloadUrl = aliPayService.queryBill(billDate, type);
        if (downloadUrl == null) {
            return R.error().message("申请账单失败");
        }
        return R.ok().message("获取账单url成功").data("downloadUrl", downloadUrl);
    }
}
